﻿using System.Collections.Generic;
using System.IO;
using System.Web.Mvc;
using System.Web.UI;

namespace BMap
{
    public static class BaiduMapHelper
    {
        public static MvcHtmlString BaiduMap(this HtmlHelper helper, string mapId, double latitude, double longitude, int zoom)
        {
            return helper.BaiduMap(mapId, latitude, longitude, zoom, null, null);
        }

        public static MvcHtmlString BaiduMap(this HtmlHelper helper, string mapId, double latitude, double longitude, int zoom, IEnumerable<MapMarker> markers)
        {
            return helper.BaiduMap(mapId, latitude, longitude, zoom, markers, null);
        }

        public static MvcHtmlString BaiduMap(this HtmlHelper helper, string mapId, double latitude, double longitude, int zoom, IEnumerable<MapControl> ctrls)
        {
            return helper.BaiduMap(mapId, latitude, longitude, zoom, null, ctrls);
        }

        public static MvcHtmlString BaiduMap(this HtmlHelper helper, string mapId, double latitude, double longitude, int zoom, IEnumerable<MapMarker> markers, IEnumerable<MapControl> ctrls)
        {
            var stringWriter = new StringWriter();
            var writer = new HtmlTextWriter(stringWriter);
            writer.RenderJsInclude(mapId);
            writer.FuncBegin(mapId);
            writer.InitMap(mapId, latitude, longitude,zoom);
            writer.RenderMapMarker(mapId, markers);
            writer.RenderMapControl(mapId, ctrls);
            writer.FuncEnd();
            return MvcHtmlString.Create(stringWriter.GetStringBuilder().ToString());
        }
    }
}
